//---------------------------------------------------------------------------

#ifndef uVisualiseH
#define uVisualiseH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include "CEdit.h"
#include "CEditNum.h"
#include "CEditUpDown.h"
#include <ActnList.hpp>
#include <ComCtrls.hpp>
#include <Controls.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
#include <Forms.hpp>
#include <ImgList.hpp>
#include <StdCtrls.hpp>
#include <ToolWin.hpp>
#include <list>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ToolWin.hpp>
#include <ImgList.hpp>
#include <ExtCtrls.hpp>
#include <ActnList.hpp>
#include <Dialogs.hpp>
#include "CEdit.h"
#include "CEditNum.h"
#include "uDocument.h"
#include "cedit.h"
#include "ceditnum.h"
#include "uEtat.h"
#include "CEditUpDown.h"

typedef struct
{
    TDocument* Doc;
    TEtat* Etat;
    TList  *LstOfPages;
    int FirstPage;
//    PAGE* __fastcall GetPage(int nNPage);
}CARAC_DOCUMENT;

class PAGE
{
public :
    TBookmark    Bookmark;
    TStringList *LstCpCalcCol;
    TList       *LstCpExtensibles,
                *LstCpEnCours;
    TYPE_BANDE   wTypeFirstBande;
    WORD         wNiveauFirstBande;
    DWORD        NiveauTypeBandeAvUtil, NiveauTypeBandeApUtil;
    TEtat        *AutreEtat;
    PAGE         *PageAutreEtat;
    int          IndiceRepetitionBande;
    bool         bAutoLoop;
    AnsiString   EMFFile;
    TCanvas     *EMFCanvas;
    bool         ReportFinPageAffiche;

    __fastcall PAGE();
    virtual __fastcall ~PAGE();
    PAGE* __fastcall GetPageAAfficher(int *pnNiveau, TEtat* &e);
};
typedef void __fastcall (__closure *TOnParamVisu  )       ( int &NbCopies);

//---------------------------------------------------------------------------
class ETATAPI TFrmVisualise;
class DocumentAImprimer
{
  public :
    CARAC_DOCUMENT *CaracDoc;
    int indexDocDansCombo;
};
class TFrmVisualise : public TForm
{
    typedef inherited TForm;


typedef std::list<DocumentAImprimer> ListeDocumentsAImprimer;


__published:	// Composants gérés par l'EDI
    TScrollBox *ScbVisu;
    TImage *ImVisu;
    TToolButton *ToolDocPrec;
    TToolButton *ToolDocSuiv;
    TToolButton *ToolImprime;
    CEditNum *edPage;
    TComboBox *CbDocument;
    TComboBox *cbZoom;
    TToolButton *ToolQuitte;
    TActionList *LstAct;
    TAction *ActQuitter;
    TAction *ActDocPrec;
    TAction *ActDocSuiv;
    TImageList *ilFichierEnable;
    TImageList *ilFichierDisable;
    TAction *ActPageSuiv;
    TAction *ActPagePrec;
    TToolButton *ToolPagePrec;
    TToolButton *ToolPageSuiv;
    TPrintDialog *PrintDialog1;
    TToolButton *ToolPdf;
    TAction *ActPdf;
    TSaveDialog *SaveDialog1;
    TToolButton *ToolHelp;
    TAction *ActHelp;
    TToolButton *ToolButton1;
    TToolButton *ToolButton3;
    TAction *ActPageEnd;
    TAction *ActPageDeb;
    TStatusBar *StVisu;
    TToolButton *ToolMail;
    TAction *ActMail;
    TToolBar *toolbar;
    TPanel *panel;
    TAction *ActImprimer;
    TPanel *lblLangue;
    CEditUpDown *edLangue;
    TToolButton *SepLangue;
    TAction *ActParametrage;
    TAction *ActGED;
    TToolButton *ToolGED;
    void __fastcall edPageChange(TObject *Sender);
    void __fastcall CbDocumentChange(TObject *Sender);
    void __fastcall cbZoomChange(TObject *Sender);
    void __fastcall ActUpdate(TObject *Sender);
    void __fastcall ActPagePrecExecute(TObject *Sender);
    void __fastcall ActPageSuivExecute(TObject *Sender);
    void __fastcall ActQuitterExecute(TObject *Sender);
    void __fastcall ActDocPrecExecute(TObject *Sender);
    void __fastcall ActDocSuivExecute(TObject *Sender);
    void __fastcall PrintDialog1Show(TObject *Sender);
    void __fastcall ActPdfExecute(TObject *Sender);
    void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
    void __fastcall ActHelpExecute(TObject *Sender);
    void __fastcall ActPageDebExecute(TObject *Sender);
    void __fastcall ActPageEndExecute(TObject *Sender);
    void __fastcall ActMailExecute(TObject *Sender);
    void __fastcall ActImprimerExecute(TObject *Sender);
    void __fastcall LstActExecute(TBasicAction *Action, bool &Handled);
    void __fastcall edLangueChange(TObject *Sender);
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall ActParametrageExecute(TObject *Sender);
  void __fastcall FormMouseWheel(TObject *Sender, TShiftState Shift,
          int WheelDelta, TPoint &MousePos, bool &Handled);
  void __fastcall ScbVisuMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall ScbVisuMouseMove(TObject *Sender, TShiftState Shift,
          int X, int Y);
  void __fastcall ScbVisuMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall ImVisuMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall ImVisuMouseMove(TObject *Sender, TShiftState Shift,
          int X, int Y);
  void __fastcall ImVisuMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall FormResize(TObject *Sender);
    void __fastcall VerifBoutton(TObject *Sender);
private:	// Déclarations utilisateur
    TWndMethod m_OldWindowProc_;

    TWndMethod m_OldWindowProcCbDocument;
    bool       m_CbDocumentTenirCompteDuProchainDestroy;
    TWndMethod m_OldWindowProccbZoom;
    void __fastcall SubClassWndProcCbDocument(Messages::TMessage &Message);
    void __fastcall SubClassWndProccbZoom(Messages::TMessage &Message);
    bool                   m_bAnnulee, m_bConceptionBefore,m_bBouttonVisu;


    int                    m_OldResolution, m_OldResol;
    int                    m_DocHeight;
    int                    m_DocWidth;
    bool                   m_ShowNbCopies;
    bool                   m_ImpressionFaite;
    AnsiString             m_asArboGED;

//    TList                 *m_LstDocument;
    TNotifyEvent           f_OnDebutPage;
    TNotifyEvent           f_OnFinPage;
    TOnDocEventInterne     f_OnDebutDoc;
    TOnEtatEventInterne    f_OnDebutEtat;
    TOnSQLParamsEventInterne f_OnSQLParams;
    TOnEtatEventInterne    f_OnBDInitialized;
    TOnBandeEventInterne   f_OnFirstBandeEtat;
    TOnBandeEventInterne   f_OnBande;
    TOnConstBandeEventInterne   f_OnAfterFirstBandeInit;
    TOnChampEventInterne   f_OnChamp;
    TOnTableauEventInterne f_OnTableau;
    TOnEtatEventInterne    f_OnFinEtat;
    TOnDocEventInterne     f_OnFinDoc;
    TOnErrorEvent          f_OnError;
    TOnVariableEvent       f_OnVariable;
    TEtat                 *etatPrec;
    bool                   m_bPrintOnly;
    TCanvas               *m_OldSupport;
    TEICPrinter           *m_OldPrinter;
    bool                   m_PDFInactif, m_bGEDEICInstalle;
    bool                   m_bSepareImpGroupe;
    bool                   m_UnClassementParDocument;
    bool                   m_bClassManuel; //true si on effectue un classement manuel
    TPoint                 m_Drag;
    Graphics::TBitmap     *m_ptrBitMap;
    ListeDocumentsAImprimer _listeDocsAImprimer;

    void __fastcall DebutPageEvent(   TObject* Sender);
    void __fastcall FinPageEvent(TObject* Sender);
    bool __fastcall OnDebutDocEvent(  TDocument  *Doc);
    bool __fastcall OnFinDocEvent(    TDocument  *Doc);
    bool __fastcall OnDebutEtatEvent( TEtat      *Etat);
    bool __fastcall OnSQLParamsEvent( TEtat      *Etat, TParams * SQLParams);
    bool __fastcall OnBDInitializedEvent( TEtat  *Etat);
    bool __fastcall OnFinEtatEvent(   TEtat      *Etat);
    bool __fastcall OnFirstBandeEtatEvent(TBande     *Bande);
    bool __fastcall OnBandeEvent(     TBande     *Bande);
    void __fastcall OnAfterFirstBandeInitEvent( const TBande     *Bande);
    bool __fastcall OnChampEvent(     TCpChamp   *Champ);
    bool __fastcall OnTableauEvent(   TCpTableau *Tableau);
    void __fastcall OnErrorEvent( const TObject *o, const AnsiString &Message);
    bool __fastcall OnVariableEvent( const TObject *o, const AnsiString &Variable, TFieldType &Type, AnsiString &Valeur);

    void __fastcall RecupereDebutPage( const TEtat *Etat, const TBande *FirstOnNewPage, PAGE* p, bool EtatPlusHautNiveau);
    void __fastcall InitialiseDebutPage( const TEtat *Etat, PAGE* p);

    bool __fastcall AfficheEMF( const TEtat* Etat, PAGE *p);
    void __fastcall InitPage( const TEtat* Etat);
    void __fastcall AffichePage( TCanvas *canvas, int nFirstPage, int nLastPage, bool bRefresh = false, MyCBarre *Bar=NULL);
    bool __fastcall DebutCaptureGED(Variant *pvGedEIC, const WideString &Classement, bool bSansClassementGED, int &DestGED, const AnsiString &NomDocument);
    void __fastcall GenerePDF(const AnsiString &asFile);
public:		// Déclarations utilisateur
    TOnParamVisu    fParamVisu;

    __property TNotifyEvent           OnDebutPage       = { read=f_OnDebutPage, write=f_OnDebutPage};
    __property TNotifyEvent           OnFinPage         = { read=f_OnFinPage,   write=f_OnFinPage};
    __property TOnDocEventInterne     OnDebutDoc        = { read=f_OnDebutDoc,  write=f_OnDebutDoc};
    __property TOnEtatEventInterne    OnDebutEtat       = { read=f_OnDebutEtat, write=f_OnDebutEtat};
    __property TOnSQLParamsEventInterne OnSQLParams     = { read=f_OnSQLParams, write=f_OnSQLParams};
    __property TOnEtatEventInterne    OnBDInitialized   = { read=f_OnBDInitialized, write=f_OnBDInitialized};
    __property TOnBandeEventInterne   OnFirstBandeEtat  = { read=f_OnFirstBandeEtat,write=f_OnFirstBandeEtat};
    __property TOnBandeEventInterne   OnBande           = { read=f_OnBande,     write=f_OnBande};
    __property TOnConstBandeEventInterne OnAfterFirstBandeInit = { read=f_OnAfterFirstBandeInit, write=f_OnAfterFirstBandeInit};
    __property TOnChampEventInterne   OnChamp           = { read=f_OnChamp,     write=f_OnChamp};
    __property TOnTableauEventInterne OnTableau         = { read=f_OnTableau,   write=f_OnTableau};
    __property TOnEtatEventInterne    OnFinEtat         = { read=f_OnFinEtat,   write=f_OnFinEtat};
    __property TOnDocEventInterne     OnFinDoc          = { read=f_OnFinDoc,    write=f_OnFinDoc};
    __property TOnErrorEvent          OnError           = { read=f_OnError,     write=f_OnError};
    __property TOnVariableEvent       OnVariable        = { read=f_OnVariable,  write=f_OnVariable};
    __property bool                   ShowNbCopies      = { read=m_ShowNbCopies,write=m_ShowNbCopies};
    __property bool                   Annulee           = { read=m_bAnnulee };
    __property bool                   ImpressionFaite   = { read=m_ImpressionFaite };
    __property bool                   bPrintOnly        = { read=m_bPrintOnly,write=m_bPrintOnly};
    __property bool                   PDFInactif        = { read=m_PDFInactif,write=m_PDFInactif};

    __property AnsiString             asArboGED         = { read=m_asArboGED,write=m_asArboGED};
    __property ListeDocumentsAImprimer ListeDocsAImprimer = {read=_listeDocsAImprimer, write=_listeDocsAImprimer};

    __fastcall TFrmVisualise(TComponent* Owner);
    virtual __fastcall ~TFrmVisualise();
    //void __fastcall Ajoute( TDocument* Doc);
    void __fastcall Ajoute( TDocument* Doc, int nPageCourante=0);
    TEtat* __fastcall Ajoute( TEtat* Etat, bool bWithDocOrigin, unsigned long Tag);
    void __fastcall Connecte( TDocument* Doc);
    void __fastcall Deconnecte( TDocument* Doc);
    int  __fastcall ShowModal();
    void __fastcall FreeAllPages(int n=-1);

};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
TFrmVisualise * ETATAPI __fastcall NewTFrmVisualise(TComponent* Owner, const AnsiString &SessionName);
void            ETATAPI __fastcall DeleteTFrmVisualise(TFrmVisualise* Owner );
//---------------------------------------------------------------------------
#endif
